package com.gouaixin.bee.beeframework2.model;

import com.gouaixin.bee.beeframework2.tool.mLog;

/**
 * Created by Administrator on 2015/4/22.
 */
//id编码控制器
public class EncodeIdModel {

    //用旧id合成8位数新id的算法
    public static String encodeId(String oldIdStr) {
        double oldId=Double.parseDouble(oldIdStr);

        int lenth=oldIdStr.length();

        mLog.e("拓展的id:长度为=" + lenth);

        mLog.e("拓展的id:初始值=" + oldId);

        oldId=Math.pow(oldId+111,6);
        mLog.e("拓展的id:+111乘方6后=" + oldId);

        java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        String m=nf.format(oldId);
        mLog.e("拓展的id:去除科学计数法=" + m);

        String idQianZui=m.substring(0,7-lenth);
        mLog.e("拓展的id:截取前缀=" + idQianZui);

        return lenth+idQianZui+oldIdStr;
    }

    //将新id解码的算法
    public static String decodeId(String newIdStr) {
        int all=newIdStr.length();
        mLog.e("newid:长度为=" + all);

        char a=newIdStr.charAt(0);
        int lenth=Integer.parseInt(a+"");
        mLog.e("oldid:长度为=" + lenth);

        String oldIdStr=newIdStr.substring(8-lenth,8);

        mLog.e("oldid:数字为=" + oldIdStr);

        return oldIdStr;
    }

    //用新id计算出相关联的系统红娘的id
    public static String decodeServiceId(String newIdStr) {
        double oldId=Double.parseDouble(newIdStr);

        int lenth=newIdStr.length();

        mLog.e("服务的id:长度为=" + lenth);

        mLog.e("服务的id:初始值=" + oldId);

        oldId=Math.pow(oldId+111,6);
        mLog.e("服务的id:+111乘方6后=" + oldId);

        java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        String m=nf.format(oldId);
        mLog.e("服务的id:去除科学计数法=" + m);

        String idQianZui=m.substring(0,4);
        mLog.e("拓展的id:截取前缀=" + idQianZui);

        return idQianZui;
    }
}
